﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using VAdvantage.DSProcessWorkflow;
using System.IO;
using VAdvantage.Apps;
using VAdvantage.Utility;
using VAdvantage.Model;
using System.Data.SqlClient;
using System.Data;
using System.Text;
using VAdvantage.Process;
using System.ComponentModel;
using VAdvantage.DataBase;
using VAdvantage.Classes;
using System.Threading;
using VAdvantage.Controls;
using SL4PopupMenu;

using VAdvantage.Grids;
using VAdvantage.Framework;
using VAdvantage.ProcessEngine;


using System.Reflection;
using SilverlightDesktop.Controls;

namespace VAdvantage.Print
{
    public interface IPdfViewer
    {
        Query SetQuery { get; set; }
        int AD_PrintFormat_ID { get; set; }
    }

    public partial class PdfViewer : CFrame
    {

        public PdfViewer(byte[] bytes, int _AD_Table_ID, ProcessInfo _pi)
        {
            InitializeComponent();
            Envs.RegisterWindowForm(this);

            Type type = Envs.GetC1ModuleType("VC1Module.UI.PdfViewer");

            if (type != null)
            {
                System.Reflection.ConstructorInfo constructor = null;
                try
                {
                    constructor = type.GetConstructor(new Type[] { typeof(byte[]), typeof(int), typeof(ProcessInfo), typeof(Form) });
                }
                catch (Exception e)
                {
                    VAdvantage.Logging.VLogger.Get().Warning("No transaction Constructor for " + type.FullName + " (" + e.ToString() + ")");
                }
                if (constructor != null)
                {
                    try
                    {
                        _ctrl = (IPdfViewer)constructor.Invoke(new object[] { bytes, _AD_Table_ID, _pi, this });
                        container.Children.Add(_ctrl as UIElement);
                    }
                    catch (Exception e)
                    {
                        VAdvantage.Logging.VLogger.Get().Warning("Invoke Erorr Class " + type.FullName + " (" + e.ToString() + ")");
                    }
                }
                else
                {
                    VAdvantage.Logging.VLogger.Get().Warning("No Std Const Found");
                }
            }

        }

        private IPdfViewer _ctrl = null;

        public PdfViewer(byte[] bytes, int _AD_Table_ID, string _AD_TableName)
            : base(Msg.GetMsg("ReportViewer"))
        {
            InitializeComponent();
            Envs.RegisterWindowForm(this);
            Type type = Envs.GetC1ModuleType("VC1Module.UI.PdfViewer");

            if (type != null)
            {
                System.Reflection.ConstructorInfo constructor = null;
                try
                {
                    constructor = type.GetConstructor(new Type[] { typeof(byte[]), typeof(int), typeof(String), typeof(Form) });
                }
                catch (Exception e)
                {
                  VAdvantage.Logging.VLogger.Get().Warning("No transaction Constructor for " + type.FullName + " (" + e.ToString() + ")");
                }
                if (constructor != null)
                {
                    try
                    {
                         _ctrl = (IPdfViewer)constructor.Invoke(new object[] { bytes, _AD_Table_ID, _AD_TableName, this });
                        container.Children.Add(_ctrl as UIElement);
                    }
                    catch (Exception e)
                    {
                        VAdvantage.Logging.VLogger.Get().Warning("Invoke Erorr Class " + type.FullName + " (" + e.ToString() + ")");
                    }
                }
                else
                {
                    VAdvantage.Logging.VLogger.Get().Warning("No Std Const Found"); 
                }
            }
            
        }

        public Query SetQuery { get { if (_ctrl != null) return _ctrl.SetQuery; return null; } set { if (_ctrl != null) _ctrl.SetQuery = value; } }

        public int AD_PrintFormat_ID { get { if (_ctrl != null) return _ctrl.AD_PrintFormat_ID;  return 0; } set { if (_ctrl != null) _ctrl.AD_PrintFormat_ID  = value; } }
    }
}
